<?php

//namespace Predis;
namespace app\common;


//require __DIR__.'/../vendor/predis/predis/examples/shared.php';

use Predis\Client;

class R
{

    private $redisClient;

    public function __construct()
    {
        $Predis_Parameters = array(
            'host' => '112.124.111.211',
            'port' => 6379,
            'password' => 'mmlove!=12',
            'database' => 1
        );
        $Predis_Options = array('prefix' => 'open_');
        if($this->redisClient == null){
            $this->redisClient = new Client($Predis_Parameters, $Predis_Options);
        }
    }

    public static function get($key)
    {
        $Redis = new R();
        return unserialize($Redis->redisClient->get($key));
    }

    public static function set($key, $val, $expire=3600)
    {
        $val = serialize($val);
        $Redis = new R();
        return $Redis->redisClient->setex($key, $expire, $val);
    }

    public static function rpush($key, $val)
    {
        $Redis = new R();
        return $Redis->redisClient->rpush($key, $val);
    }
    
    public static function lpop($key) {
        $Redis = new R();
        return $Redis->redisClient->lpop($key);
    }

    public static function lpush($key, $val)
    {
        $Redis = new R();
        return $Redis->redisClient->lpush($key, $val);
    }

    public static function lrange($key, $start=0, $stop=-1)
    {
        $Redis = new R();
        return $Redis->redisClient->lrange($key, $start, $stop);
    }





}